package zmee.pur.src.formplugin;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;

/**
 * @Author: xw
 * @Date: 2023/03/13/10:19
 * @Description: 提交将【中标金额汇总】.【供应商】/【中标含税金额】带到定标单
 */
public class DecisionBillPlugin extends AbstractBillPlugIn {

    @Override
    public void afterDoOperation(AfterDoOperationEventArgs args) {
        String operateKey = args.getOperateKey();
        if ("submit".equals(operateKey)) {
            Object id = this.getModel().getValue("id");
            QFilter filter = new QFilter("parentid", QCP.equals, id);
            DynamicObject decisionSum = BusinessDataServiceHelper.loadSingle("src_decisionsum_sup", "entryentity.supplier,entryentity" +
                    ".taxamount", filter.toArray());
            if (decisionSum != null) {
                DynamicObjectCollection entryEntity = decisionSum.getDynamicObjectCollection("entryentity");
                if (!entryEntity.isEmpty()) {
                    this.getModel().setValue("zmee_supplier", entryEntity.get(0).get("supplier"));
                    this.getModel().setValue("zmee_taxamount", entryEntity.get(0).get("taxamount"));
                    DynamicObject dataEntity = this.getModel().getDataEntity(true);
                    SaveServiceHelper.save(new DynamicObject[]{dataEntity});
                }
            }
        }
    }
}
